//
//  ViewController.swift
//  任意路径动画
//
//  Created by app on 2017/4/14.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var imageView:UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        
        imageView = UIImageView()
        imageView.frame = CGRect(x: 50, y: 50, width: 50, height: 50)
        imageView.backgroundColor = UIColor.red
        imageView.image = UIImage(named: "")
        view.addSubview(imageView)
        let pathLine = CGMutablePath()
        // 直线移动
        pathLine.move(to: CGPoint(x: 50, y: 50))
//        pathLine.addLine(to:CGPoint(x: 300, y: 50))
//        pathLine.move(to:CGPoint(x: 300, y: 50))
//        pathLine.addLine(to: CGPoint(x: 300, y: 300))
        
        pathLine.addArc(center: CGPoint(x:200,y:200), radius: 150, startAngle: 0, endAngle: CGFloat(M_PI_2), clockwise: true)
        let animation = CAKeyframeAnimation()
        animation.duration = 2
        animation.path = pathLine
        animation.keyPath = "position"
        animation.fillMode = kCAFillModeForwards
        animation.isRemovedOnCompletion = false
        imageView.layer.add(animation, forKey: nil)
        
    }


}

